import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
import QtMultimedia

ApplicationWindow {
    id: mainWindow
    width: 640
    height: 480
    visible: true
    title: qsTr("乐其影音")
    flags: Qt.Window | Qt.FramelessWindowHint

    Material.theme: Material.Dark
    Material.accent: Material.Purple

    property alias source: mediaPlayer.source

    MediaPlayer {
        id: mediaPlayer

        videoOutput: videoOutput
        audioOutput: AudioOutput {
            id: audio
            muted: false
            volume: 0.5
        }
    }

    TitleBar {
        id: titleBar

        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: videoOutput.top

        visible: !videoOutput.fullScreen

        mainWindow: mainWindow
        mediaPlayer: mediaPlayer
        videoOutput: videoOutput

        onFullScreen: {
            parent.fullScreen ? showNormal() : showFullScreen()
            parent.fullScreen = !parent.fullScreen
        }

        onMinimizeWindow: mainWindow.showMinimized()
        onCloseWindow: mainWindow.close()
    }

    VideoOutput {
        id: videoOutput
        property bool fullScreen: false

        anchors.top: fullScreen ? parent.top : titleBar.bottom
        anchors.left: parent.left
        anchors.right: parent.right
    }
}
